with Wagons;
with Ada.Text_Io; use Ada.Text_Io;
with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;

package body Wagons is

   function Contenance (W :Wagon ) return Positive is
   begin
      case W.Model is
         when Salle =>
            return ContenuSalle;
         when Compartiment =>
            return  Taille_Compartiment * W.Nb_Compart;
      end case;
   end Contenance ;

   function Saisir return Wagon is
      P_Wagon : access Wagon;
   begin
      Put_Line("Saisissez le type de Wagon(Salle/Compartiment)" );
      declare
         Ty : Type_Wagon;
      begin
         Ty := Type_Wagon'Value(Get_Line);
         P_Wagon := new Wagon(Ty);
         if Ty = Compartiment then
            Put_Line("donner le nombre de compartiments");
            declare
               Nb : Positive;
            begin
               Nb := Positive'Value(Get_Line);
               P_Wagon.all.Nb_Compart := Nb;
            end;
         end if;
         return P_Wagon.all;
      end;
   end;

   procedure Afficher( W: Wagon) is
   begin
      case W.Model is
         when Salle =>
            Put_Line("Salle de : "& Positive'Image(ContenuSalle));
         when Compartiment =>
            Put_Line("Composé de : "&Positive'Image(W.Nb_Compart)&" compartiments de "&Positive'Image(Taille_Compartiment)&" places.");
      end case;
   end Afficher;


end Wagons;
